package com.guigu.qingcheng.controller;

import com.guigu.qingcheng.pojo.user.TbAddress;
import com.guigu.qingcheng.pojo.user.TbUser;
import com.guigu.qingcheng.service.UserFeign;
import com.guigu.qingcheng.utils.JwtUtils;
import com.guigu.qingcheng.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserFeign feign;

    @GetMapping("findAddressList")
    public List<TbAddress> findAddressList(){
        String username = "lijialong";
        return feign.findAddressList(username);
    }

    @PostMapping("loginUser")
    @ResponseBody
    public R loginUser (@RequestBody TbUser tbUser) {
        return feign.loginUser(tbUser);
    }

    @GetMapping("getUserInfo")
    @ResponseBody
    public R getUserInfo(HttpServletRequest request) {
        System.out.println(request);
        String username = JwtUtils.getMemberIdByJwtToken(request);
        System.out.println(username);
        return feign.getUserInfo(username);
    }

    @GetMapping("sm")
    @ResponseBody
    public String getWxCode(){
        return feign.getWxCode();
    }
}
